package com.lovecaa;

import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * 拉模式-随机获取queue消息
 * 创建时间： 2023年10月21日 11:41:00
 *
 * @author Mr.Tao
 * @since 1.0.0
 */
public class LitePullConsumer {
    public static void main(String[] args) throws MQClientException {
        DefaultLitePullConsumer consumer = new DefaultLitePullConsumer();
        consumer.setConsumerGroup("LitePullConsumer");
        consumer.setNamesrvAddr("192.168.192.110:9876");
        consumer.subscribe("TopicTest", "*");
        consumer.start();
        while (true) {
            List<MessageExt> messageExtList = consumer.poll();
            System.out.println("消息拉取成功");
            for (MessageExt messageExt : messageExtList) {
                System.out.println("消息消费成功：" + messageExt);
            }
        }
    }
}
